package logic

import (
	"context"
	"wechat/api/internal/svc"
	"wechat/api/internal/types"
	"wechat/wechatrpc/wechatrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type WeAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewWeAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WeAddLogic {
	return &WeAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *WeAddLogic) WeAdd(req *types.WeAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.WeCharRpc.WeAdd(l.ctx, &wechatrpc.WeAddRequest{
		Image:        req.Image,
		NickName:     req.NickName,
		WeiXinNumber: req.WeiXinNumber,
		Address:      req.Address,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "个人信息添加成功",
		Data:    add,
		Code:    200,
	}, nil
}
